import java.util.Scanner;

/*
*@author weijiayi
* */
public class ShapeAreaCalculator{

    private static final String SQUARE="正⽅形";
    private static final String CIRCLE="圆形";
    private static final String TRIANGLE="三⻆形";
    private static final String TRAPEZOID="梯形";
    public static void main(String[] args){
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输⼊形状名称（正⽅形、圆形、三⻆形或梯形）：");
        String shape=scanner.nextLine().trim().toLowerCase();
        if(SQUARE.equals(shape)){
            calculateSquareArea(scanner);
        }else if(CIRCLE.equals(shape)){
            calculateCircleArea(scanner);
        }else if(TRIANGLE.equals(shape)){
            calculateTriangleArea(scanner);
        }else if(TRAPEZOID.equals(shape)){
            calculateTrapezoidArea(scanner);
        }else{
            System.out.println("不⽀持的形状类型。");
        }
        scanner.close();
    }
    /**
     *计算正⽅形⾯积的⽅法*@param scanner⽤于接收⽤户输⼊的Scanner对象*/
    public static void calculateSquareArea(Scanner scanner){
        System.out.println("请输⼊正⽅形的边⻓：");
        double side=scanner.nextDouble();
        System.out.println("正⽅形的⾯积是："+squareArea(side));
    }
    /**
     *计算圆形⾯积的⽅法*@param scanner⽤于接收⽤户输⼊的Scanner对象*/
    public static void calculateCircleArea(Scanner scanner){
        System.out.println("请输⼊圆形的半径：");
        double radius=scanner.nextDouble();
        System.out.println("圆形的⾯积是："+circleArea(radius));
    }
    /**
     *计算三⻆形⾯积的⽅法*@param scanner⽤于接收⽤户输⼊的Scanner对象*/
    public static void calculateTriangleArea(Scanner scanner){
        System.out.println("请输⼊三⻆形的三条边⻓：");
        double a=scanner.nextDouble();
        double b=scanner.nextDouble();
        double c=scanner.nextDouble();
        System.out.println("三⻆形的⾯积是："+triangleArea(a,b,c));
    }
    /**
     *计算梯形⾯积的⽅法*@param scanner⽤于接收⽤户输⼊的Scanner对象*/
    public static void calculateTrapezoidArea(Scanner scanner){
        System.out.println("请输⼊梯形的上底⻓度：");
        double base1=scanner.nextDouble();
        System.out.println("请输⼊梯形的下底⻓度：");
        double base2=scanner.nextDouble();
        System.out.println("请输⼊梯形的⾼：");
        double height=scanner.nextDouble();
        System.out.println("梯形的⾯积是："+trapezoidArea(base1,base2,height));
    }
    /**
     *计算正⽅形⾯积的静态⽅法*@param side正⽅形的边⻓*@return返回正⽅形的⾯积*/
    public static double squareArea(double side){
        return side*side;
    }
    /**
     *计算圆形⾯积的静态⽅法*@param radius圆形的半径*@return返回圆形的⾯积*/
    public static double circleArea(double radius){
        return Math.PI*radius*radius;
    }
    /**
     *计算三⻆形⾯积的静态⽅法（使⽤海伦公式）*@param a三⻆形的第⼀条边⻓*@param b三⻆形的第⼆条边⻓*@param c三⻆形的第三条边⻓*@return返回三⻆形的⾯积*/
    public static double triangleArea(double a,double b,double c){
        double s=(a+b+c)/2;
        return Math.sqrt(s*(s-a)*(s-b)*(s-c));
    }
    /**
     *计算梯形⾯积的静态⽅法*@param base1梯形的上底⻓度*@param base2梯形的下底⻓度*@param height梯形的⾼*@return返回梯形的⾯积*/
    public static double trapezoidArea(double base1,double base2,double height){
        return(base1+base2)*height/2;
    }

}
